package com.studies.mycenter.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.studies.common.R.R;
import com.studies.mycenter.pojo.Activity;
import com.studies.mycenter.pojo.BaseInfo;
import com.studies.mycenter.service.ActivityService;
import com.studies.mycenter.service.BaseInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 基地 前端控制器
 * </p>
 *
 * @author 研学活动后台
 * @since 2019-12-24
 */
@Api(tags="活动模块")
@CrossOrigin //跨域
@RestController
@RequestMapping("/mycenter/base-info")
public class BaseInfoController {

    @Autowired
    private BaseInfoService baseInfo;

    @ApiOperation(value = "分页基地列表")
    @GetMapping(value = "{page}/{limit}")
    public R selectPage(@ApiParam(name = "page", value = "当前页码", required = true)
                        @PathVariable Long page,

                        @ApiParam(name = "limit", value = "每页记录数", required = true)
                        @PathVariable Long limit){

        Page<BaseInfo> pageParam = new Page<BaseInfo>(page, limit);

        Map<String, Object> map = baseInfo.qryBaseInfoPage(pageParam);

        return  R.ok().data(map);
    }

    @ApiOperation(value = "根据ID查询")
    @GetMapping(value = "{id}")
    public R getById(
            @ApiParam(name = "id", value = "ID", required = true)
            @PathVariable String id) {

        //根据id查询
        List<BaseInfo> courseList = baseInfo.selectByBaseInfoId(id);

        return R.ok().data("courseList", courseList);
    }

    @ApiOperation(value = "根据ID修改")
    @PutMapping("{id}")
    public R updateById(
            @ApiParam(name = "id", value = "ID", required = true)
            @PathVariable Integer id,
            @ApiParam(name = "baseInfo", value = "对象", required = true)
            @RequestBody BaseInfo baseInfo) {
        baseInfo.setId(id);
        this.baseInfo.updateById(baseInfo);
        return R.ok();
    }

    @ApiOperation(value = "根据ID删除")
    @DeleteMapping
    public R removeById(@ApiParam(name = "id", value = "章节ID", required = true) @PathVariable String id) {
        baseInfo.removeById(id);
        return R.ok();
    }
}

